package com.shxt.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.shxt.PageBean;
import com.shxt.model.Client;
import com.shxt.service.ClientService;

@Controller
public class ClientController {
    @Autowired
    private ClientService clientService;
    @RequestMapping("cli/list")
    public String listClient(String query,Client client,Map<String , Object> map,@RequestParam(required=false,defaultValue="1") int pages,@RequestParam(required=false,defaultValue="1") int p,HttpServletRequest request,String msg){
        map = PageBean.serverMap(map ,client , pages);
        
        map.put("query" , query);
        List<Client> clientList = clientService.clientList(map , request);
        
        Integer count = clientService.count(map);
        
        map = PageBean.map(map , client.getClass() , clientList , count , pages);
        
        map.put("p" , p);
        map.put("count" , count);

        map.put("msg" , msg);
        
        System.out.println(query);
        
        return "client/client";
    }

    //删除联系人信息
    @RequestMapping("cli/del")
    public String del(String client_ids,HttpServletRequest request, Map<String , Object> map,String query,Client client){

        int flg = clientService.delete(client_ids);
        String msg = new String();
        if(flg>0){
            msg="删除成功！";
        }else{
            msg = "删除失败，请重新尝试！";
        }
        
        return listClient(query ,client,map  , 1 , 1, request,msg);

    }

}
